from sys import stdin
from Token import Token

class Lexer:
	def __init__(self):
		self.l = ""

	def nextToken(self):
		if (len(self.l) == 0):
			c = str(stdin.read(1))
			s = ""

			while(c.isdigit()):
				s += c
				c = str(stdin.read(1))

			if (len(s) > 0):
				t = Token(s, "INT")
				self.l = c
				return t

			else:
				if (c == " "):
					return self.nextToken()
				else:
					return self.__toToken(c)

		else:
			if (self.l == " "):
				self.l = ""
				return self.nextToken()
			else:
				x = self.l
				self.l = ""
				return self.__toToken(x)


	def __toToken(self, c):
		t = None

		if (c == "*"):
			t = Token(c, "MULT")
				
		elif (c == "+"):
			t = Token(c, "PLUS")
					
		elif (c == "("):
			t = Token(c, "LPAREN")
				
		elif (c == ")"):
			t = Token(c, "RPAREN")

		elif (c == "\n"):
			t = Token(c, "END")

		else:
			t = Token(c, "ERROR")

		return t